﻿using System;
using System.Collections.Generic;
 
using System.Text;
using System.Runtime.InteropServices;


namespace HDF5
{
    using hid_t = System.Int32;
    using herr_t = System.Int32;
    using hsize_t = System.UInt64;
    using hssize_t = System.Int64;
    using hunsigned = System.UInt32;

    using hbool_t = System.UInt32;
    using htri_t = System.Int32;
    using ssize_t = System.Int64;

    using haddr_t = System.UInt64;

    using uint32_t = System.UInt32;
    using uint64_t = System.UInt64;

    using H5O_msg_crt_idx_t = System.UInt32;

    using size_t = System.UInt32;

    using off_t = System.Int32;

    using H5E_major_t = System.Int32;
    using H5E_minor_t = System.Int32;

    using time_t = System.Int64;
    using H5Z_filter_t = System.Int32;  


    #region structs
    public struct H5A_info_t
    {
        hbool_t corder_valid;
        H5O_msg_crt_idx_t corder;         /* Creation order                 */
        H5T_cset_t cset;           /* Character set of attribute name */
        hsize_t data_size;      /* Size of raw data		  */
    }
    #endregion structs

    #region Delegates
    public delegate herr_t H5A_operator2_t(hid_t location_id, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name, ref  H5A_info_t ainfo, IntPtr op_data);
    public delegate herr_t H5A_operator1_t(hid_t location_id, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name, IntPtr operator_data);
    #endregion Delegates

    public static class H5A
    {


   
        /// <summary>
        /// import H5A Attribute functions
        /// </summary>
        #region Attribute Functions
        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Acreate(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Acreate(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id);


        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Acreate2(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Acreate_by_name(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, [In] [MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t lapl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Aopen(hid_t obj_id, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t aapl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Aopen_by_name(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, [In] [MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t aapl_id, hid_t lapl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Aopen_by_idx(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t aapl_id, hid_t lapl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern htri_t H5Aexists(hid_t obj_id, [In] [MarshalAs(UnmanagedType.LPStr)] string attr_name);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern htri_t H5Aexists_by_name(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, [In] [MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t lapl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Arename(hid_t loc_id, StringBuilder old_attr_name, StringBuilder new_attr_name);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Arename_by_name(hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, [In][MarshalAs(UnmanagedType.LPStr)] string old_attr_name, [In][MarshalAs(UnmanagedType.LPStr)] string new_attr_name, hid_t lapl_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Awrite(hid_t attr_id, hid_t mem_type_id, IntPtr buf);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aread(hid_t attr_id, hid_t mem_type_id, IntPtr buf);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aclose(hid_t attr_id);

        //[DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        //public static extern herr_t H5Aiterate(hid_t loc_id, [Out] hunsigned idx, H5A_operator_t op, IntPtr op_data);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aiterate(hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, ref hsize_t n, H5A_operator2_t op, IntPtr op_data);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aiterate2( hid_t obj_id, H5_index_t idx_type, H5_iter_order_t order, ref hsize_t n, H5A_operator2_t op, IntPtr op_data ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aiterate_by_name( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, H5_index_t idx_type, H5_iter_order_t order, ref hsize_t n, H5A_operator2_t op, IntPtr op_data, hid_t lapd_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Adelete( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Adelete_by_name( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name, hid_t lapl_id );

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Adelete_by_idx( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id );

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aget_info(hid_t attr_id, ref H5A_info_t ainfo);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aget_info_by_name( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, [In][MarshalAs(UnmanagedType.LPStr)] string attr_name,ref H5A_info_t ainfo, hid_t lapl_id );

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Aget_info_by_idx( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, ref H5A_info_t ainfo, hid_t lapl_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern ssize_t H5Aget_name(hid_t attr_id, size_t buf_size, StringBuilder buf);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Aget_create_plist(hid_t attr_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Aget_space(hid_t attr_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Aget_type(hid_t attr_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hsize_t H5Aget_storage_size(hid_t attr_id);

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern ssize_t H5Aget_name_by_idx( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string obj_name, H5_index_t idx_type, H5_iter_order_t order, hsize_t n, StringBuilder name, size_t size, hid_t lapl_id );

        #endregion Attribute Functions
    }
}
